package com.yzy.fly.config;

import com.yzy.fly.api.annotation.ApiListenerIgnore;
import com.yzy.fly.api.function.version.ApiVersionRequestMappingHandlerMapping;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@ApiListenerIgnore
@Configuration(proxyBeanMethods = false)
public class FlyWebMvcRegistrations implements WebMvcRegistrations {

    @Override
    public RequestMappingHandlerAdapter getRequestMappingHandlerAdapter() {
        return new FlyRequestMappingHandlerAdapter();
    }

    @Override
    public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
        ApiVersionRequestMappingHandlerMapping apiVersionRequestMappingHandlerMapping = new ApiVersionRequestMappingHandlerMapping();
//        apiVersionRequestMappingHandlerMapping.setOrder(Ordered.HIGHEST_PRECEDENCE);
//        apiVersionRequestMappingHandlerMapping.setOrder(Ordered.LOWEST_PRECEDENCE);
        return apiVersionRequestMappingHandlerMapping;
    }

    @Override
    public  ExceptionHandlerExceptionResolver getExceptionHandlerExceptionResolver() {
        return new FlyExceptionHandlerExceptionResolver();
    }

}
